#!/usr/bin/env python
#coding:utf-8
from sgmllib import SGMLParser

class URLLister(SGMLParser):
    def reset(self):
        SGMLParser.reset(self)
        self.urls = []

    def start_a(self, attrs):
        href = [v for k, v in attrs if k == 'href']
        if href:
            self.urls.extend(href)

if __name__ == '__main__':
    a = '<html><head><title>test</title></head><body><a href="http://www.google.com">Google</a></body></html>'
    p = URLLister()
    p.feed(a)
    for url in p.urls:
        print url
